{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "287a46f1",
   "metadata": {},
   "source": [
    "# 第四周python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "af1095ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 上周回顾 (range())\n",
    "range(0,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b31eeb9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a2594e8b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for it in range(5):\n",
    "    print(it)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bf2dd82d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for it in range(1,5):\n",
    "    print(it)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fffac6cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for it in range(1,10,3):\n",
    "     print(it)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c56cce14",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type():检查类型\n",
    "\n",
    "> 1. 有序的数据结构 （数值 字符串）\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex\n",
    "\n",
    ">2. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "087299e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "## 1.Number(数值)\n",
    "## int类型：整点型\n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0019b508",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.3 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float类型：浮点型\n",
    "b = 11.3\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a1a0a0b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数，复数型)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4016255f",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 2.字符串（string）\n",
    "## 2.1关于字符串的基本内容\n",
    "## 2.2关于字符串的方法及函数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "57da1739",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "5b68d437",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "62d10b06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "beab281b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "04c35ca2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ba4d95c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值，这种方法我们称其为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c737fe46",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "not enough values to unpack (expected 2, got 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m## 利用for循环 遍历文本信息\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i,j \u001b[38;5;129;01min\u001b[39;00m title:\n\u001b[0;32m      3\u001b[0m     \u001b[38;5;28mprint\u001b[39m(i)\n",
      "\u001b[1;31mValueError\u001b[0m: not enough values to unpack (expected 2, got 1)"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for i,j in title:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17f38036",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "2f35dd76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "# 思考，融合判断一段文本中是否存在“广州”\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "469581ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州在这段文本中\n",
      "广州在这段文本中\n"
     ]
    }
   ],
   "source": [
    "for i,j in enumerate(title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1] ==\"州\":\n",
    "            print(\"广州在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7a6d4b91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59   in 检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "8c2583b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "## in: 检查成员对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b739d286",
   "metadata": {},
   "source": [
    "> 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a965c3ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，傻逼\n"
     ]
    }
   ],
   "source": [
    "print(\"你好，\" + \"傻逼\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49d4729f",
   "metadata": {},
   "source": [
    ">> 字符串不可以拼接数值，不可以用来运算\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "19ed2f15",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [40]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 举例\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 错误举例\n",
    "\"3\" / \"2\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e7ecb78",
   "metadata": {},
   "source": [
    "> 字符串的方法\n",
    ">> 1. .count() 检查出现数量\n",
    ">> 2. .split 进行文本拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "20acabc1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "09a060a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "## text.split"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "175bac93",
   "metadata": {},
   "source": [
    "## 练习\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "35ce0073",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州首批十大“最具获得感”改革案例出炉\n"
     ]
    }
   ],
   "source": [
    "text = \"广州首批十大“最具获得感”改革案例出炉\"\n",
    "print(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4876c852",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
